package com.ev.hr.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.ev.hr.dao.CandidateFollowDao;
import com.ev.hr.domain.CandidateFollowDO;
import com.ev.hr.service.CandidateFollowService;
import com.ev.hr.vo.CandidateFollowPageParam;
import com.ev.framework.utils.R;
import com.ev.apis.model.DsResultResponse;
import com.google.common.collect.Maps;


@Service
public class CandidateFollowServiceImpl implements CandidateFollowService {
    @Autowired
    private CandidateFollowDao candidateFollowDao;

    @Override
    public CandidateFollowDO get(Long id) {
        return candidateFollowDao.get(id);
    }

    @Override
    public List<CandidateFollowDO> list(Map<String, Object> map) {
        return candidateFollowDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return candidateFollowDao.count(map);
    }

    @Override
    public int save(CandidateFollowDO candidateFollow) {
        return candidateFollowDao.save(candidateFollow);
    }

    @Override
    public int update(CandidateFollowDO candidateFollow) {
        return candidateFollowDao.update(candidateFollow);
    }

    @Override
    public int updateAll(CandidateFollowDO candidateFollow) {
        return candidateFollowDao.updateAll(candidateFollow);
    }

    @Override
    public int remove(Long id) {
        return candidateFollowDao.remove(id);
    }

    @Override
    public int batchRemove(Long[] ids) {
        return candidateFollowDao.batchRemove(ids);
    }

    @Override
    public R saveAndVerify(CandidateFollowDO saveParam) {
        if (saveParam.getId() != null) {
            return candidateFollowDao.update(saveParam) > 0 ? R.ok() : R.error();
        }
        return candidateFollowDao.save(saveParam) > 0 ? R.ok() : R.error();
    }

    @Override
    public Map<String, Object> getById(Long id) {
        Map<String, Object> result = Maps.newHashMap();
        if (id == null) {
            return result;
        }
        CandidateFollowPageParam candidateFollowPageParam = new CandidateFollowPageParam();
        candidateFollowPageParam.setId(id);
        List<Map<String, Object>> list = candidateFollowDao.pageList(candidateFollowPageParam);

        if (list.size() > 0) {
            result.put("data", list.get(0));
        }
        return result;
    }

    @Override
    public Map<String, Object> pageList(CandidateFollowPageParam pageParam) {
        Map<String, Object> result = Maps.newHashMap();
        List<Map<String, Object>> data = candidateFollowDao.pageList(pageParam);
        int total = candidateFollowDao.pageCount(pageParam);
        result.put("data", new DsResultResponse(pageParam.getPageno(), pageParam.getPagesize(), total, data));
        return result;
    }

}
